package com.movitech.mobile.cz.base.purchase.bizcontroller;


import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.purchase.bizservice.IndexService;
import com.movitech.mobile.cz.base.purchase.bizvo.*;
import com.movitech.mobile.cz.base.purchase.entity.ext.IndexMoreRequestVO;
import com.movitech.mobile.cz.base.supplier.bizservice.SSuppliersWorkFlowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 首页前端控制器
 * </p>*
 *
 * @author Movitech Mobile
 * @since 2018-02-28
 */
@RestController
@RequestMapping("/v1/login")
@Api(value = "首页接口", description = "首页接口")
public class IndexController {

    @Autowired
    @Qualifier("indexService")
    private IndexService indexService;

    @Autowired
    @Qualifier("sSuppliersWorkFlowService")
    private SSuppliersWorkFlowService sSuppliersWorkFlowService;


    @GetMapping("/public/getRestIndex")
    @ApiOperation(
            value = "采购外网平台首页接口",
            notes = "采购外网平台首页接口",
            response = IndexResponseVO.class
    )
    public RestReturnResult getRestIndex(HttpServletResponse response, HttpServletRequest request) {
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

		try{
			hResult = indexService.getRestIndex(response,request);
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}

		return hResult;
    }


    /**
	 * 首页初始化 接口
	 * @return
	 */
    @ApiOperation(
            value = "采购管理后台首页接口",
            notes = "采购管理后台首页接口",
            response = IndexResponseVO.class
    )
	@RequestMapping(value = "/initHome", method = RequestMethod.POST)
	@ResponseBody
	public RestReturnResult<Object> initHome(){
    	RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

		try{
			hResult = indexService.initHome();
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}

		return hResult;
	}

	/**
	 * 采购管理后台获取用户信息接口
	 * @return
	 */
	@ApiOperation(
			value = "采购管理后台获取用户信息+菜单接口",
			notes = "采购管理后台获取用户信息+菜单接口",
			response = CurrentUserResponseVO.class
	)
	@RequestMapping(value = "/innerUserInfo", method = RequestMethod.GET)
	@ResponseBody
	public RestReturnResult<Object> innerUserInfo(){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

		try{
			hResult = indexService.innerUserInfo();
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}

		return hResult;
	}

	/**
	 * 首页-公告通知更多 接口
	 * @return
	 */
    @ApiOperation(
            value = "首页-更多接口",
            notes = "首页-更多接口",
            response = IndexResponseVO.class
    )
	@RequestMapping(value = "/moreInfo", method = RequestMethod.POST)
	@ResponseBody
	public RestReturnResult<Object> moreInfo(@RequestBody IndexMoreRequestVO indexMoreRequestVO){
    	RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

		try{
			hResult = indexService.moreInfo(indexMoreRequestVO);
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}

		return hResult;
	}

	@ApiOperation(
			value = "外网首页-中标、招标列表接口",
			notes = "外网首页-中标、招标列表接口",
			response = IndexResponseVO.class
	)
	@RequestMapping(value = "/public/bidList", method = RequestMethod.POST)
	@ResponseBody
	public RestReturnResult<Object> bidList(@RequestBody IndexMoreRequestVO indexMoreRequestVO){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
		try{
			if("4".equals(indexMoreRequestVO.getResultType())||"5".equals(indexMoreRequestVO.getResultType())){
				hResult = indexService.bidList(indexMoreRequestVO);
			}
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}

		return hResult;
	}

	/**
	 * 采购管理后台首页公告详情 接口
	 * @param
	 * @return
	 */
    @ApiOperation(
            value = "采购管理后台首页公告详情 接口",
            notes = "采购管理后台首页公告详情 接口"
    )
	@RequestMapping(value = "/getNoticeDetail", method = RequestMethod.GET)
	@ResponseBody
	public RestReturnResult<Object> getNoticeDetail(String messageId){
    	RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

		try{
			hResult = indexService.getNoticeDetail(messageId);
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}

		return hResult;
	}

    @ApiOperation(value = "采购管理后台首页-待办详情 接口",notes = "采购管理后台首页-待办详情 接口")
	@RequestMapping(value = "/doToDoItem", method = RequestMethod.GET)
	@ResponseBody
	public RestReturnResult<Object> doToDoItem(String myDealId){
    	RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

		try{
			hResult = sSuppliersWorkFlowService.doToDoItem(myDealId);
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}

		return hResult;
	}


	/**
	 * 外网招标、中标详情接口
	 * @param messageId
	 * @return
	 */
	@ApiOperation(
			value = "外网招标、中标详情接口",
			notes = "外网招标、中标详情接口"
	)
	@RequestMapping(value = "/public/getNoticeDesc/{messageId}", method = RequestMethod.GET)
	@ResponseBody
	public RestReturnResult<Object> getNoticeDesc(@PathVariable String messageId){
		return indexService.getNoticeDesc(messageId);
	}


	@PostMapping("/initHomeForMobileSupplier")
	@ApiOperation(value = "移动端供方服务号首页", notes = "移动端供方服务号首页")
	public RestReturnResult<Object> initHomeForMobileSupplier(@RequestBody MSupplierHomeInitRequestVO vo){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS);

		hResult = indexService.initHomeForMobileSupplier(vo);

		return hResult;
	}

	@PostMapping("/getinvitationListForMobile")
	@ApiOperation(value = "邀请函列表-移动端供方服务号首页", notes = "移动端供方服务号首页")
	public RestReturnResult<Object> getinvitationListForMobile(@RequestBody MInvitationListRequestVO vo){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS);

		hResult = indexService.getinvitationListForMobile(vo);

		return hResult;
	}

	@PostMapping("/getToDoListForMobile")
	@ApiOperation(value = "待办列表-移动端供方服务号首页", notes = "移动端供方服务号首页")
	public RestReturnResult<Object> getToDoListForMobile(@RequestBody MToDoListRequestVO vo){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS);

		hResult = indexService.getToDoList(vo);

		return hResult;
	}

	@PostMapping("/getMessageListForMobile")
	@ApiOperation(value = "消息列表-移动端供方服务号首页", notes = "移动端供方服务号首页")
	public RestReturnResult<Object> getMessageListForMobile(@RequestBody MMessageListRequestVO vo){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS);

		hResult = indexService.getMessageList(vo);

		return hResult;
	}

	@PostMapping("/initHomeForMobileOwnApp")
	@ApiOperation(value = "首页-移动端甲方嵌入APP", notes = "移动端甲方嵌入APP")
	public RestReturnResult<Object> initHomeForMobileOwnApp(){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS);

		hResult = indexService.initHomeForMobileOwnApp();

		return hResult;
	}

	@PostMapping("/getToDoOrDoneListForMobileOwnApp")
	@ApiOperation(value = "现场考察/待办/已办-移动端甲方嵌入APP", notes = "移动端甲方嵌入APP")
	public RestReturnResult<Object> getToDoListForMobileOwnApp(@RequestBody MToDoListOwnAppRequestVO vo){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS);

		hResult = indexService.getToDoOrDoneListForMobileOwnApp(vo);

		return hResult;
	}

}

